#include <iostream>
#include <vector>
#include <queue>
using namespace std;
 
vector<pair<int,int>> path, res;
bool vis[13][13];
int m, n;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
 
void dfs(vector<vector<int>>& vv, int sr, int sc)
{
    path.push_back({sr, sc});
    vis[sr][sc] = true;
 
    if(sr == m - 1 && sc == n - 1)
    {
        res = path; // 一定要保存一下结果
        return;
    }
    queue<pair<int, int>> q;
    for(int j = 0; j < 4; ++j)
    {
        int x = sr + dx[j], y = sc + dy[j];
        if(x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && vv[x][y] == 0)
        {
            dfs(vv, x, y);
        }
    }
 
    path.pop_back(); // 回溯
    vis[sr][sc] = false;
}
 
int main()
{
    cin >> m >> n;
    vector<vector<int>> vv(m, vector<int>(n, 0));
    for(int i = 0; i < m; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            cin >> vv[i][j];
        }
    }
 
    dfs(vv, 0, 0);
    for(auto [a, b] : res)
    {
        cout << '(' << a << ',' << b << ')' << endl;
    }
    return 0;
}